package de.iritgo.skillfull.collision;

import java.util.LinkedList;
import java.util.List;

import de.iritgo.skillfull.component.CollisionComponent;


/**
 * The base class of the quad tree.
 * @author held
 */
public class QuadTree 
{
	private List<QuadNode> nodes = new LinkedList<QuadNode> ();
	/** The number of sub divisions allows */
	static public int MAX_DEPTH_LEVEL = 5;
	
	/** The maximum number of bodies in a given space acceptable */
	static public int MAX_COL_COMPS = 20;
	
	/** The minimum quadnode(space) size */
	static public int MIN_QUAD_SIZE  = 64;

	/** hack.. */
	static public int MULTI  = 3;

	QuadNode rootNode;

	public QuadTree () 
	{
		rootNode = new QuadNode (-256, -256, 1280 * MULTI, 1024 * MULTI, 0, null, nodes);
		nodes.add (rootNode);
	}
	
	/** Clear all nodes */
	public void init () 
	{
		nodes.clear();
	}
	
	/**
	 * Add al collision component the quad tree
	 * 
	 * @param collisionComponent The cc
	 */
	public void add (CollisionComponent collisionComponent)
	{
		rootNode.addCollisionComponent (collisionComponent);
	}

	/**
	 * Get all quad nodes in a flat list
	 * 
	 * @return The quad nodes
	 */
	public List<QuadNode> getQuadNodes () 
	{
		return nodes;
	}
}
